package me.zhengjie.request;

import lombok.Data;

public final class ATMRContext {

    private ATMRContext() {
    }

    private static final ThreadLocal<Context> THREAD_LOCAL = new ThreadLocal<>();

    public static Context init() {
        Context context = new Context();
        THREAD_LOCAL.set(context);
        return context;
    }

    public static void clear() {
        THREAD_LOCAL.remove();
    }

    public static void setContext(Context context) {
        THREAD_LOCAL.set(context);
    }

    public static Context getContext() {
        Context context = THREAD_LOCAL.get();
        if (null == context) {
            return init();
        }
        return context;
    }

    /**
     * 上下文
     */
    @Data
    public static final class Context {
        private Long memberId;
        private String openId;
    }
}
